package com.atguigu.gmallre.mock.stage;

import com.atguigu.gmallre.mock.service.LogService;
import com.atguigu.mock.util.LogUtil;
import com.atguigu.gmallre.mock.config.AppConfig;
import com.atguigu.gmallre.mock.factory.UserSession;
import com.atguigu.gmallre.mock.log.*;

import com.atguigu.gmallre.mock.log.enums.ItemType;
import com.atguigu.gmallre.mock.log.enums.PageId;

import com.atguigu.mock.util.RandomBox;
import com.atguigu.mock.util.RandomNum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("goodList")
public class GoodListStage implements Stage {

    @Autowired
    LogService logService;

    @Override
    public boolean handle() {
        AppMain mainlog = mainlog();
        logService.doLog(mainlog) ;
        UserSession.setLastPageId(PageId.good_list);
        return true;
    }


    private   AppMain      mainlog(){

        AppCommon appCommon = UserSession.getAppCommon();

        String  item=  new RandomBox(AppConfig.searchKeywords).getRandStringValue();
        Integer durTime= RandomNum.getRandInt(5000,AppConfig.page_during_max_ms);
        AppPage appPage = AppPage.builder()
                .item_type(ItemType.keyword)
                .item(item)
                .during_time(durTime)
                .last_page_id(UserSession.getLastPageId())
                .page_id(PageId.good_list).buildFinal();
        List<AppDisplay> appDisplayList = AppDisplay.builder().pos_id(10).max_size(20).buildList();

        UserSession.setLastDisplay(appDisplayList);

              UserSession.addTimeByDuringTime(durTime);
        AppMain appMain = AppMain.builder().common(appCommon).page(appPage).displays(appDisplayList) .ts(UserSession.getCurDateTime().getTime()).checkError().build();
        return  appMain;

    }
}
